package com.yy.job.console.converter;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;

import com.yy.job.common.dao.po.YYJobLogDO;
import com.yy.job.common.enums.JobActionEnum;
import com.yy.job.common.utils.date.YYDateUtils;
import com.yy.job.console.dto.JobLogView;

public class JobLogViewConverter {

	public static JobLogView convert(YYJobLogDO JobLogDO) {
		JobLogView consoleDTO = new JobLogView();
		BeanUtils.copyProperties(JobLogDO, consoleDTO);
		consoleDTO.setExecStartTimeFormat(YYDateUtils.formatDateTimeDefault(JobLogDO.getExecStartTime()));
		consoleDTO.setExecEndTimeFormat(YYDateUtils.formatDateTimeDefault(JobLogDO.getExecEndTime()));
		JobActionEnum jobAction = JobActionEnum.findByCode(JobLogDO.getJobAction());
		if(jobAction != null) {
			consoleDTO.setJobActionName(jobAction.getName());
		}
		return consoleDTO;
	}

	public static List<JobLogView> listConvert(List<YYJobLogDO> jobDOs) {
		if (jobDOs == null) {
			return null;
		}
		return jobDOs.stream().map(e -> convert(e)).collect(Collectors.toList());
	}

}
